<?php


namespace app\service;


use app\admin\model\Tag as TagModel;
use think\Db;

class TagService
{
    protected $model;
    public function __construct()
    {
        $this->model = app()->make(TagModel::class);
    }

    /**
     * 查询标签
     *
     * @param $tagName
     * @return int|string
     */
    public function queryByName ($tagName) {
        return $this->model->where(array("name"=>$tagName))->find();
    }

    /**
     * 查询标签
     *
     * @param $id
     * @return int|string
     */
    public function queryById ($id) {
        return $this->model->where(array("id"=>$id))->find();
    }

    /**
     * @param int $limit
     * @param string $order
     * @return TagModel[]|array|\think\Collection
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\DbException
     * @throws \think\db\exception\ModelNotFoundException
     */
    public function queryList ($limit = 50, $order = 'created_time desc') {
        return $this->model->order($order)->limit($limit)->select();
    }
}